package com.handpay.nocardpay.baselibrary.bankmanager.view.fragment;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.handpay.nocardpay.baselibrary.R;
import com.handpay.nocardpay.baselibrary.commbase.view.fragment.BaseFragment;
import com.handpay.nocardpay.baselibrary.config.SecureManager;
import com.handpay.nocardpay.baselibrary.main.mine.model.bean.MerchInfo;
import com.handpay.nocardpay.baselibrary.utils.BankUtils;
import com.handpay.nocardpay.baselibrary.utils.CommonUtils;

/**
 * Created by sxshi on 2017/8/15.
 */

public class BankManagerFragment extends BaseFragment {
    private ImageView bank_type_logo;
    private TextView bank_name, cardhander_name, cardno, bank_address;
    private Button modify_bankcard;

    private String mSubBankCode;
    private String mBankProvinceId, mBankAreaId;
    private String mBankProvinceName, mBankAreaName, mSubBankName;
    private String cardNum;

    private MerchInfo merchInfo;

    public static BankManagerFragment newInstance(MerchInfo merchInfo) {
        Bundle args = new Bundle();
        args.putParcelable("merchInfo", merchInfo);
        BankManagerFragment fragment = new BankManagerFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_bankmanager;
    }

    @Override
    public String getFragmentTitle() {
        return getString(R.string.mine_bankmanager);
    }

    @Override
    public void initView(View view) {
        Toolbar mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
        initToolbar(mToolbar, true);

        bank_type_logo = (ImageView) view.findViewById(R.id.bank_type_logo);
        modify_bankcard = (Button) view.findViewById(R.id.modify_bankcard);
        bank_name = (TextView) view.findViewById(R.id.bank_name);
        cardhander_name = (TextView) view.findViewById(R.id.cardhander_name);
        cardno = (TextView) view.findViewById(R.id.cardno);
        bank_address = (TextView) view.findViewById(R.id.bank_address);
    }

    @Override
    public void initListener() {
        modify_bankcard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (merchInfo != null) {
                    startWithPop(ModifyBankFragment.newInstance(merchInfo));
                }
            }
        });
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        this.merchInfo = getArguments().getParcelable("merchInfo");

        String bankName = merchInfo.getBankName();
        mSubBankName = merchInfo.getSubBranchName();
        cardNum = merchInfo.getCardNum();
        String name = merchInfo.getName();
        mBankProvinceId = merchInfo.getProvinceId();
        mBankProvinceName = merchInfo.getProvinceName();
        mBankAreaId = merchInfo.getAreaId();
        mBankAreaName = merchInfo.getAreaName();

        mSubBankCode = merchInfo.getSubBankCode();
        if (!TextUtils.isEmpty(mSubBankCode)) {
            bank_address.setText(mSubBankName);
        } else {
            bank_address.setText("");
        }
        cardhander_name.setText(name);
        bank_name.setText(bankName);
        cardno.setText(CommonUtils.formattingCard(cardNum));
        bank_type_logo.setImageResource(BankUtils.getBankIcon(bankName));
    }

}
